<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Iperplot extends Model
{
    protected $table = 'dd_iperplot';
    protected $primaryKey = 'plotid';
    public $timestamps = false;
    protected $guarded = array();
    public static function addIperPlot(\Illuminate\Http\Request $request, $iperid) {
        static::where('iperid', $iperid)->delete();
        if (!$request->has('plots')) {
            return array('status'=>1, 'info'=>"操作成功");
        }
        $plots = explode(',', $request->input('plots'));
        $data = array_map(function($val) use ($iperid){
            return array('plotid'=>$val, 'iperid'=>$iperid);
        }, $plots);
        $res = static::insert($data);
        if ($res)
            return array('status'=>1, 'info'=>"分配成功");
        else 
            return array('status'=>0, 'info'=> '分配失败');
    }
}
